<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %> 
<head>
	 <jsp:include page="/views/include.jsp"></jsp:include>
	 <script type="text/javascript">
		$.parser.onComplete = function(){
            $('body').css('visibility','visible');
            setTimeout(function(){
	        	$('#loading-mask').remove();
            },50);
        };
        
        function ajaxLoading(){ 
            $("<div class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:$(window).height()}).appendTo("body"); 
            $("<div class=\"datagrid-mask-msg\"></div>").html("正在处理，请稍候。。。").appendTo("body").css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2});
         } 
        
         function ajaxLoadEnd(){ 
             $(".datagrid-mask").remove(); 
             $(".datagrid-mask-msg").remove();             
        }
        
        
		$(function() {
			$(window).resize(function(){
            	$('#mainlayout').layout('resize');
            });
			
			$('#dlg').dialog({
				onOpen:function(){
					$('#dt_excel').datagrid('resize');
				}
			});
		});
	
		function refresh(){
			$('#dt_excel').datagrid('loadData', {total:0,rows:[]});
			$('#dt_excel').datagrid('load',{});
		}
	
		
		
		function updateItem() {
			$('#update-excel-form').form('submit', {
				url:'<c:url value="/etl/excel_update.tg"/>',
				onSubmit:function() { return true; },
				dataType:"json",
				success:function(result) {
					var data = eval("(" + result + ")");
					if(data.success) {
						$.messager.show({
							title		:	'提示ʾ',
							msg			:	'操作成功!',
							showType	:	'slide'
						});
						$('#update-excel-dialog').dialog('close');
						$('#dt_excel').datagrid('loadData', {total:0,rows:[]});
						$('#dt_excel').datagrid("reload");
					} else {
						$.messager.alert('操作失败!','error');
					}
				}
			});
		}
		
		function ignore(value){
			 if(window.confirm("确定要忽略该错误吗?")){
				 $.ajax({
						url : 'etl/error_ignoreError.tg',
						type : "post",
						dataType : "json",
						data : {errorLogId : value},
						beforeSend:ajaxLoading,
						success : function (result) {
							ajaxLoadEnd(); 
							$('#dt_excel').datagrid('loadData', {total:0,rows:[]});
							$('#dt_excel').datagrid("reload");
							data=eval(result);
							alert(data.msg);
						}
					});
			 }
		}
		function ignoreAll(){
			 if(window.confirm("确定要忽略所有错误吗?")){
				 $.ajax({
						url : "<c:url value='/etl/error_ignoreAllError.tg?excelId=${excelId}'/>",
						type : "get",
						dataType : "json",
						beforeSend:ajaxLoading,
						success : function (result) {
							ajaxLoadEnd(); 
							$('#dt_excel').datagrid('loadData', {total:0,rows:[]});
							$('#dt_excel').datagrid("reload");
							data=eval(result);
							alert(data.msg);
						}
					});
			 }
		}
		
		
		function rexcute(value){
			 if(window.confirm("确定要执行错误记录吗?")){
				 $.ajax({
						url : 'etl/error_rexcuteError.tg',
						type : "post",
						dataType : "json",
						data : {errorLogId : value},
						beforeSend:ajaxLoading,
						success : function (result) {
							ajaxLoadEnd(); 
							$('#dt_excel').datagrid('loadData', {total:0,rows:[]});
							$('#dt_excel').datagrid("reload");
							data=eval(result);
							alert(data.msg);
						}
					});
			 }
		}
		function rexcuteAll(){
			 if(window.confirm("确定要执行所有错误记录错误吗?")){
				 $.ajax({
						url : "<c:url value='/etl/error_rexcuteAllError.tg?excelId=${excelId}'/>",
						type : "get",
						dataType : "json",
						beforeSend:ajaxLoading,
						success : function (result) {
							ajaxLoadEnd(); 
							$('#dt_excel').datagrid('loadData', {total:0,rows:[]});
							$('#dt_excel').datagrid("reload");
							data=eval(result);
							alert(data.msg);
						}
					});
			 }
		}
		
		 
		function errorsFormatter(value, row , index){
			if(row.status == 1) {
				return "";
			}
			
			if(row.status == 2) {
				return "<a href=\"javascript:rexcute(" + value + ")\" class=\"easyui-linkbutton\" iconCls=\"icon-edit\" plain=\"true\">重新执行</a>";
			}
			
			return "<a href=\"javascript:ignore(" + value + ")\" class=\"easyui-linkbutton\" iconCls=\"icon-edit\" plain=\"true\">忽略</a> | <a href=\"javascript:rexcute(" + value + ")\" class=\"easyui-linkbutton\" iconCls=\"icon-edit\" plain=\"true\">重新执行</a>";
		}
		
		function statusFormatter(value){
			 switch (value) {
			case 0:
				return "未处理";
				break;
			case 1:
				return "已处理";
				break;
			case 2:
				return "已忽略";
				break;
			default:
				return "未知";
				break;
			}
		}
	</script>
	 
	 
</head>
	<body style="margin:0;padding:0;height:100%;overflow:hidden;background:#F2FBFF">
  			<div id="mainlayout" class="easyui-layout" fit="true">
			<div region="north" border="false">
				<div class="toolbar">
					<table cellpadding="0" cellspacing="0" style="width:95%;height=30px;">
						<tr>
							<td>
								<a href="javascript:ignoreAll()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">忽略所有</a>
								<a href="javascript:rexcuteAll()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">重新执行所有</a>
							</td>
						</tr>
					</table>
				</div>
			</div>
			
		<!-- 上传Excel Dialog  -->
		<div region="center" border="false">
			<table id="dt_excel" class="easyui-datagrid"
						url="<c:url value='/etl/error_excelError.tg?excelId=${excelId}'/>"
						fit="true" border="false" 
						pagination="true" striped="true" fitColumns="true"					
						singleSelect="true" rownumbers="true">
				<thead>
				
					<th field="excel_name" width="50" >Excel名称</th>
					<th field="date" width="60" >时间</th>
					<th field="excelColumn_Index" width="20" >行索引</th>
					<th field="errorLog_cause" width="250" >错误原因</th>
					<th field="status" width="60" formatter="statusFormatter">状态</th>
					<th field="errorLog_id" width="100"  formatter="errorsFormatter">处理方式</th>
				</thead>
			</table>
		</div>
	
	</div>

</body>